<script>
	export default {
		globalData: {
			appid: 'ttb2dfc4622de58bd4',
			barHeight: 0, // 导航栏高度
			menuButtonInfo: {}, // 小程序胶囊信息
			openid: '',
			isAdvert: true,
			videoAd:'',
			gameInfo: {},
		},
		methods: {
			updateTips() { // 检查版本更新
				const updateManager = uni.getUpdateManager()
				updateManager.onCheckForUpdate(function(res) {
					console.log(res)
				})

				updateManager.onUpdateReady(function(res) {
					uni.showModal({
						title: '更新提示',
						content: '新版本已经准备好，是否重启应用？',
						success(res) {
							if (res.confirm) {
								// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
								updateManager.applyUpdate();
							}
						}
					})

				})

				updateManager.onUpdateFailed(function(res) {
					// 新的版本下载失败
					console.log("版本下载失败原因", err);
					uni.showToast({
						title: "新版本下载失败，请稍后再试",
						icon: "none",
					})
				})
			},

			getAppInfo() { // 获取设备信息
				const appInfo = uni.getStorageSync('appinfo')
				if (appInfo) {
					this.globalData.barHeight = appInfo.barHeight
					this.globalData.menuButtonInfo = appInfo.menuButtonInfo
				} else {
					const result = {}
					uni.getSystemInfo({
						success: (res) => {
							result.barHeight = res.statusBarHeight
							result.menuButtonInfo = uni.getMenuButtonBoundingClientRect()
							if(result){
								uni.setStorageSync('appinfo', result)
								this.getAppInfo()
							}
						}
					})
				}
			}
		},
		onLaunch: function(options) {
			this.getAppInfo()  
			this.updateTips() 
		}
	}
</script>

<style>
	@import "./static/css/base.scss";

	#app {
		/* background-image: url(@/static/img/load.gif); */
		background-repeat: no-repeat;
		background-position: center;
		background-size: contain;
		min-width: 100vw;
		min-height: 100vh;
		background-color: #FFFFFF;
	}
</style>
